<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>注册/登录</title>
	<meta name="viewport" content="width=device-width, initial-scale=1  maximum-scale=1 user-scalable=no">
	<meta name="mobile-web-app-capable" content="注册/登录">
	<meta name="apple-mobile-web-app-capable" content="注册/登录">
	<meta name="apple-touch-fullscreen" content="注册/登录">
	<meta name="HandheldFriendly" content="注册/登录">

	<link rel="stylesheet" href="${request.contextPath}/statics/css/materialize.css">
	<link rel="stylesheet" href="${request.contextPath}/statics/font-awesome/css/font-awesome.min.css">
	<link rel="stylesheet" href="${request.contextPath}/statics/css/normalize.css">
	<link rel="stylesheet" href="${request.contextPath}/statics/css/owl.carousel.css">
	<link rel="stylesheet" href="${request.contextPath}/statics/css/owl.theme.css">
	<link rel="stylesheet" href="${request.contextPath}/statics/css/owl.transitions.css">
	<link rel="stylesheet" href="${request.contextPath}/statics/css/fakeLoader.css">
	<link rel="stylesheet" href="${request.contextPath}/statics/css/style.css">
	<style>
		.form-field{
			color: #000000;
			font-size: 16px;
			line-height: 32px;
		}

	</style>
</head>
<body>
	<!-- contact us -->
	<div class="pages section" style="padding-top: 100px;">
		<div class="container">
			<div class="contact-us">
				<div class="row">
					<div class="col s12">
							<div class="form-group">
								<label class="form-field">学生姓名 <label style="color: #E60012;">*</label> </label>
							</div>
							<div class="form-group">
								<input type="text" class="validate" id="userName" name="userName" placeholder="请输入姓名" required>
							</div>
							<div class="form-group">
								<label class="form-field">学生身份证号 <label style="color: #E60012;">*</label> </label>
							</div>
							<div class="form-group">
								<input type="email" id="idCard" name="idCard" placeholder="请输入身份证号" required>
							</div>
							<div class="form-group">
								<label class="form-field">单位</label>
							</div>
							<div class="form-group">
								<input type="email" id="company" name="company" placeholder="请输入单位" required>
							</div>

							<div class="form-group" style="margin-top: 15px;padding: 0 10%">
								<button class="btn button-default" type="button" onclick="signup()">立即认证</button>
							</div>

					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- end contact us -->
	
<!-- loader -->
	<div id="fakeLoader"></div>
	<!-- end loader -->

	
	<!-- scripts -->
	<script src="${request.contextPath}/statics/js/jquery.min.js"></script>
	<script src="${request.contextPath}/statics/js/materialize.min.js"></script>
	<script src="${request.contextPath}/statics/js/owl.carousel.min.js"></script>
	<script src="${request.contextPath}/statics/js/fakeLoader.min.js"></script>
	<script src="${request.contextPath}/statics/js/contact-form.js"></script>
	<script src="${request.contextPath}/statics/js/main.js"></script>

	<script>
		function signup(){
			var userName = $("#userName").val();
			if(!userName){
				alert("请输入学生姓名");
				return;
			}
			var idCard = $("#idCard").val();
			if(!idCard){
				alert("请输入学生身份证号");
				return;
			}
			if(!isChinaIDCard(idCard)){
				alert("请输入正确的身份证号");
				return;
			}
			var sex = getChinaIDCardGender(idCard);

			var company = $("#company").val();
			if(!company){
				alert("请输入单位");
				return;
			}

			$.ajax({
				type: 'GET',
				url: '${request.contextPath}/h5/reg?backUrl=${backUrl!}',
				data: {
					userName: userName,
					idCard: idCard,
					company: company,
					sex: sex
				},
				success: function (res) {
					console.log(res);
					if(res.code === 0){
						window.location.href="${request.contextPath}/h5/exam-list";
					}else if(res.code === 201){
						window.location.href="${request.contextPath}"+res.msg;
					}else{
						alert(res.msg);
					}
				}
			})
		}

		// 校验身份证号
		function isChinaIDCard(str) {
			var re = new RegExp('^[1-9]\\d{5}(19|20)\\d{2}(0[1-9]|1[0-2])([0-2][1-9]|[1-3][0-1])\\d{3}([0-9]|X)$');
			return re.test(str);
		}

		// 取性别 1男 0女
		function getChinaIDCardGender(str) {
			var genderCode = str.charAt(16);
			return genderCode % 2 === 1 ? "1" : "0";
		}



	</script>

</body>
</html>
